home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / Qpopper / pop_parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-01  |  2.5 KB  |  85 lines

  1. /*
  2.  * Copyright (c) 1989 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef lint
  8. static char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  9. static char SccsId[] = "@(#)@(#)pop_parse.c    2.1  2.1 3/18/91";
  10. #endif not lint
  11.  
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #include <ctype.h>
  15. #include "popper.h"
  16.  
  17. /* 
  18.  *  parse:  Parse a raw input line from a POP client 
  19.  *  into null-delimited tokens
  20.  */
  21.  
  22. pop_parse(p,buf)
  23. POP         *   p;
  24. char        *   buf;        /*  Pointer to a message containing 
  25.                                 the line from the client */
  26. {
  27.     char            *   mp;
  28.     register int        i;
  29.     
  30.     /*  Loop through the POP command array */
  31.     for (mp = buf, i = 0; ; i++) {
  32.     
  33.         /*  Skip leading spaces and tabs in the message */
  34.         while (isspace(*mp))mp++;
  35.  
  36.         /*  Are we at the end of the message? */
  37.         if (*mp == 0) break;
  38.  
  39.         /*  Have we already obtained the maximum allowable parameters? */
  40.         if (i >= MAXPARMCOUNT) {
  41.             pop_msg(p,POP_FAILURE,"Too many arguments supplied.");
  42.             return(-1);
  43.         }
  44.  
  45.         /*  Point to the start of the token */
  46.         p->pop_parm[i] = mp;
  47.  
  48.         /*  Search for the first space character (end of the token) */
  49.         while (!isspace(*mp) && *mp) mp++;
  50.  
  51.         /*  Delimit the token with a null */
  52.         if (*mp) *mp++ = 0;
  53.  
  54.      if (i == 0) {
  55.        /*  Convert the first token (POP command) to lower case */
  56.        pop_lower(p->pop_command);
  57.        /*
  58.         * This is kinda gross.  Passwords have to be parsed diffrently
  59.         * as they may contain spaces.  If you think of a cleaner way,
  60.         * do it.  The "p->pop_command[0] == 'p'" is so save a call to
  61.         * strcmp() on ever call to pop_parse();  This parsing keeps
  62.        * leading and trailing speces behind for the password command.
  63.         */
  64.        if(p->pop_command[0] == 'p' && strcmp(p->pop_command,"pass") == 0) {
  65.          if (*mp != 0) {
  66.            p->pop_parm[1] = mp;
  67.               if (strlen(mp) > 0) {
  68.                 mp = mp + strlen(mp) - 1;
  69.                 while (*mp == 0xa || *mp == 0xd) *mp-- = 0;
  70.               }
  71.            return(1);
  72.          } else
  73.            return (-1);
  74.        }
  75.      }
  76.     }
  77.  
  78.     /*  Were any parameters passed at all? */
  79.     if (i == 0) return (-1);
  80.  
  81.     /*  Return the number of tokens extracted minus the command itself */
  82.     return (i-1);
  83.     
  84. }
  85.